package cc.wanforme.chipmunity.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.wanforme.chipmunity.common.bean.WebResponse;
import cc.wanforme.chipmunity.controller.base.BaseController;
import cc.wanforme.chipmunity.system.po.TopPassage;
import cc.wanforme.chipmunity.system.service.interfaces.TopPassageService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/topp")
public class TopPassageController extends BaseController {
	private static final Logger log = LoggerFactory.getLogger(TopPassageController.class);
	
	
	@Autowired
	private TopPassageService topPassageService;

	@RequestMapping("/add")
	@ResponseBody
	@ApiOperation("添加置顶文章")
	@ApiImplicitParam(name="topPassage", dataType="TopPassage", value="添加置顶文章", required=true)
	@PreAuthorize("hasAuthority('topp:add')")
	public WebResponse addMessage(@RequestBody(required=true) TopPassage topPassage) {
		try {
			return topPassageService.addTopPassage(topPassage);
		} catch (Exception e) {
			log.error("添加文章置顶", e);
			return WebResponse.fail("更新失败！服务器异常！");
		}
	}
	
	@RequestMapping("/update")
	@ResponseBody
	@ApiOperation("更新置顶文章")
	@ApiImplicitParam(name="topPassage", dataType="TopPassage", value="更新置顶文章", required=true)
	@PreAuthorize("hasAuthority('topp:update')")
	public WebResponse updateMessage(@RequestBody(required=true) TopPassage topPassage) {
		try {
			return topPassageService.updateTopPassage(topPassage);
		} catch (Exception e) {
			log.error("更新文章置顶", e);
			return WebResponse.fail("更新失败！服务器异常！");
		}
	}
	
}
